Imports System.Data.Common
Partial Class Presentation_ViewReports
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim MyParams(0) As GenParameter
        Dim Sql As String
        Dim CountSql As String
        Dim SortOrder As String

        Page.Title = "View your complete reports"

        CountSql = "SELECT COUNT(*) " & _
            "FROM Actionmaster INNER JOIN (ExecutiveMaster INNER JOIN (ClientMaster INNER JOIN WorkflowMaster ON ClientMaster.ClientID = WorkflowMaster.ClientID) ON ExecutiveMaster.ExecutiveID = WorkflowMaster.ExecutiveID) ON Actionmaster.ActionID = WorkflowMaster.ActionID " & _
            "WHERE ExecutiveMaster.ExecutiveUserName = ?ExecutiveName "

        Sql = "SELECT Date_Format(WorkflowMaster.MeetingDate,'%d/%m/%Y') AS 'MeetingDate', ClientMaster.ClientName, ActionMaster.ActionDescription, WorkflowMaster.Details, WorkflowMaster.NextAction, Date_Format(WorkflowMaster.DateofNextAction,'%d/%m/%Y') AS 'Date of Next Action' " & _
                "FROM Actionmaster INNER JOIN (ExecutiveMaster INNER JOIN (ClientMaster INNER JOIN WorkflowMaster ON ClientMaster.ClientID = WorkflowMaster.ClientID) ON ExecutiveMaster.ExecutiveID = WorkflowMaster.ExecutiveID) ON Actionmaster.ActionID = WorkflowMaster.ActionID " & _
                "WHERE ExecutiveMaster.ExecutiveUserName = ?ExecutiveName"



        MyParams(0) = New GenParameter("?ExecutiveName", User.Identity.Name, Data.DbType.String)

        'Store the Sort Choice

        Select Case SelectSort.SelectedValue

            Case "NameSort"
                SortOrder = " ORDER BY ClientName"
            Case "DateSort"
                SortOrder = " ORDER BY MeetingDate desc"
            Case Else
                SortOrder = " ORDER BY ClientName"
        End Select

        Sql = Sql & SortOrder

        'Feed the values into the grid

        ViewReports.Sql = Sql
        ViewReports.CountSql = CountSql
        ViewReports.ShowButton = True
        ViewReports.Params = MyParams

    End Sub
End Class
